The world is not yet flat: Transport costs matter!

(c) Kristian Behrens, W. Mark Brown, and Théophile Bougna

—

Important information on compiling and running the C codes.


The GNU Scientific Libraries have to be linked (in particular libgsl.a). They are available at https://www.gnu.org/software/gsl/. We used version 1.16 of the libraries.

All header search paths and library search paths have to be fully specified in the build options. The code was developed on a MacPro/MacBookPro running OS 10.12 and 10.13. The SDK version is macOS 10.12). The code was also tested on older SDKs. Please make sure that you use the correct SDK, segmentation faults may result from improper specifications of the SDK.

For the implementation at Statistics Canada, the code was compiled on a Microsoft server using Visual C++.


The command line structure for running the executable is as follows:

./[EXEC_NAME] ./input_file.txt ./[OUTPUT_FILE] ./[BORDER_NAME] num1 num2 num3 num4 num5

—

EXEC_NAME		= name of the executable you produced

input_file.txt		= file that contains the plants to be processed

location_list.txt	= file that contains the list of sampling spaces to be used (see example; each line is a filename containing the counterfactuals that are associated with the corresponding sample in inlist.txt)

OUTPUT_FILE		= name of the output file to be created

BORDER_NAME		= name of the file containing the border crossings with the US

numX			= minimum distance to the numX nearest plants; specify five values for X (e.g., 3 5 10 15 25)

—

Here is a sample test and output (using only 5000 plants for illustrative purposes):


C33175:mindist behrens_k$ ./mindist2 ./small_sample_plants.txt ./output.txt ./border_crossings.txt 3 5 7 10 15

./mindist2: Processing the file with the plants...
./mindist2: Number of plants to be processed = 5000
./mindist2: Computing across 3 5 7 10 15 nearest plants
./mindist2: Number of border crossings to be used = 118
./mindist2: Starting to compute the minimum distances...
Iteration 0 done
Iteration 100 done
Iteration 200 done
Iteration 300 done
Iteration 400 done
Iteration 500 done
Iteration 600 done
Iteration 700 done
Iteration 800 done
Iteration 900 done
Iteration 1000 done
Iteration 1100 done
Iteration 1200 done
Iteration 1300 done
Iteration 1400 done
Iteration 1500 done
Iteration 1600 done
Iteration 1700 done
Iteration 1800 done
Iteration 1900 done
Iteration 2000 done
Iteration 2100 done
Iteration 2200 done
Iteration 2300 done
Iteration 2400 done
Iteration 2500 done
Iteration 2600 done
Iteration 2700 done
Iteration 2800 done
Iteration 2900 done
Iteration 3000 done
Iteration 3100 done
Iteration 3200 done
Iteration 3300 done
Iteration 3400 done
Iteration 3500 done
Iteration 3600 done
Iteration 3700 done
Iteration 3800 done
Iteration 3900 done
Iteration 4000 done
Iteration 4100 done
Iteration 4200 done
Iteration 4300 done
Iteration 4400 done
Iteration 4500 done
Iteration 4600 done
Iteration 4700 done
Iteration 4800 done
Iteration 4900 done
./mindist2: Elapsed time = 4d seconds


—

File structures:

The files with the plants have the following structure:

First line: Number of observations (plants)
Other lines: plant_id latitude longitude industry_code weight

(NOTE: industry_code and weight need to be specified but are not used)

The files with the border crossings have the following structure:

First line: Number of crossings
Other lines: latitude longitude rail_flag road_flag

(NOTE: rail_flag and road_flag need to be specified but are not used)


Each file must have the number of observations and lines matching, else there will be segmentation faults. Sample files are provided with the code for illustrative purposes. We also provide a MacOS X 10.13 precompiled executable (mindist_exec). Please run this as a command-line tool in the terminal.
